package com.mh.service;

import com.mh.entity.BookType;
import com.mh.jdbc.entity.IPage;
import com.mh.jdbc.exception.DAOException;
import com.mh.jdbc.util.JdbcDao;

public class BookTypeService {
	/**
	 * 书名唯一性校验
	 * @param bookType
	 * @return
	 */
	public boolean bookNameifCanInsert(String bookTypeName){
		try {
			BookType bookType = new BookType();
			bookType.setBookTypeName(bookTypeName);
			return JdbcDao.ifCanInsert(bookType, "bookTypeName");
		} catch (DAOException e) {
			throw new RuntimeException(e);
		}
	}
	/**
	 * 图书类型添加
	 * @param bookType
	 * @return
	 */
	public int bookTypeAdd(BookType bookType){
		try {
			return JdbcDao.insert(bookType);
		} catch (DAOException e) {
			throw new RuntimeException(e);
		}
	}
	/**
	 * 图书类型修改
	 * @param bookType
	 * @return
	 */
	public int bookTypeEdit(BookType bookType){
		try {
			return JdbcDao.update(bookType, "id");
		} catch (DAOException e) {
			throw new RuntimeException(e);
		}
	}
	/**
	 * 图书类型删除
	 * @param bookType
	 * @return
	 */
	public int bookTypeDelete(BookType bookType){
		try {
			return JdbcDao.delete(bookType);
		} catch (DAOException e) {
			throw new RuntimeException(e);
		}
	}
	/**
	 * 图书类型查询
	 * @param iPage
	 * @return
	 */
	public IPage<BookType> bookTypeFindList(IPage<BookType> iPage){
		try {
			return JdbcDao.queryForPageLeftLikeWhere(iPage);
		} catch (DAOException e) {
			throw new RuntimeException(e);
		}
	}
}
